package com.shop2cn.iapi.promotion.testcase;

import java.util.Arrays;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.promotion.parameter.GetSingleProductPromotionPolicyReq;
import com.shop2cn.iapi.promotion.parameter.GetSingleProductPromotionPolicyResp;
import com.shop2cn.iapi.promotion.parameter.PromotionPolicyDto;
import com.shop2cn.iapi.promotion.serivce.GetProductPromotionPolicyCall;
import com.shop2cn.iapi.promotion.serivce.PromotionInfoVerify;
import com.shop2cn.iapi.sellerpromotion.parameter.CreatePromotionBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.Shop2cnSellerPromotionCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
/**
*获取买手商品促销策略信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetProductPromotionPolicy{
	private static GetSingleProductPromotionPolicyReq getproductpromotionpolicyBean;
	private static GetProductPromotionPolicyCall getproductpromotionpolicyCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取买手商品促销策略信息");
	}

	@Before
	public void caseUp() {
		getproductpromotionpolicyBean=new GetSingleProductPromotionPolicyReq();
		getproductpromotionpolicyCall=new GetProductPromotionPolicyCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getproductpromotionpolicyCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductPromotionPolicy_001() {
		Logger.start(true,"获取买手商品促销策略信息");
		try {
			Integer sellerid = GodmchManageCallService.CreateSellerMch();
			String pid =TestDataManager.getRandomUUID().toString();
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(sellerid, 4);
			createpromotionBean.setProductIdList(Arrays.asList(pid));
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
			
			Thread.sleep(1000);
			
			getproductpromotionpolicyBean.setSellerId(sellerid);
			getproductpromotionpolicyBean.setProductId(pid);
			getproductpromotionpolicyBean.setCurrency("CNY");
			getproductpromotionpolicyCall.setData(getproductpromotionpolicyBean);
			getproductpromotionpolicyCall.callService();		
			
			Logger.verifyEquals("200", getproductpromotionpolicyCall.getString("Code"), "验证返回Code");
			 GetSingleProductPromotionPolicyResp resp = getproductpromotionpolicyCall.getData();
			Logger.verifyEquals(getproductpromotionpolicyBean.getProductId(), resp.getProductId(), "验证返回Code");

			// 验证PromotionInfo
			List<String> productIds = createpromotionBean.getProductIdList();
			for ( PromotionPolicyDto promotionPolicy : resp.getPromotionPolicyDtos()) {
				
				Logger.verifyEquals(promotionId, promotionPolicy.getPromotionId(), "验证返回promotionId");

				PromotionInfoVerify promotionInfoVerify = new PromotionInfoVerify();
				promotionInfoVerify.verifyPromotionPolicyInDB(promotionPolicy);
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetProductPromotionPolicy_002() {
		Logger.start(true,"获取买手商品促销策略信息-活动已取消");
		try {
			Integer sellerid = GodmchManageCallService.CreateSellerMch();
			String pid =TestDataManager.getRandomUUID().toString();
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(sellerid, 4);
			createpromotionBean.setProductIdList(Arrays.asList(pid));
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
			Shop2cnSellerPromotionCallService.EndAllEnablePromotion(sellerid);
			Thread.sleep(1000);
			getproductpromotionpolicyBean.setSellerId(sellerid);
			getproductpromotionpolicyBean.setProductId(pid);
			getproductpromotionpolicyBean.setCurrency("CNY");
			getproductpromotionpolicyCall.setData(getproductpromotionpolicyBean);
			getproductpromotionpolicyCall.callService();		
			
			Logger.verifyEquals("200",getproductpromotionpolicyCall.getString("Code"), "验证返回Code");
			Logger.verifyEquals(null, getproductpromotionpolicyCall.getData(), "验证返回Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetProductPromotionPolicy_003() {
		Logger.start(true,"获取买手商品促销策略信息-活动未开始");
		try {
			Integer sellerid = GodmchManageCallService.CreateSellerMch();
			String pid =TestDataManager.getRandomUUID().toString();
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(sellerid, 4);
			createpromotionBean.setBegin(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			createpromotionBean.setEnd(YMTDateUtil.getBeforeOrNextDay(2,"yyyy-MM-dd HH:mm:ss"));
			createpromotionBean.setProductIdList(Arrays.asList(pid));
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);

			getproductpromotionpolicyBean.setSellerId(sellerid);
			getproductpromotionpolicyBean.setProductId(pid);
			getproductpromotionpolicyBean.setCurrency("CNY");
			getproductpromotionpolicyCall.setData(getproductpromotionpolicyBean);
			getproductpromotionpolicyCall.callService();		
			
			Logger.verifyEquals("200",getproductpromotionpolicyCall.getString("Code"), "验证返回Code");
			Logger.verifyEquals(null, getproductpromotionpolicyCall.getData(), "验证返回Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetProductPromotionPolicy_004() {
		Logger.start(true,"获取买手商品促销策略信息-sellerid空");
		try {
			Integer sellerid = GodmchManageCallService.CreateSellerMch();
			String pid =TestDataManager.getRandomUUID().toString();
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(sellerid, 4);
			createpromotionBean.setProductIdList(Arrays.asList(pid));
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);

//			getproductpromotionpolicyBean.setSellerId(sellerid);
			getproductpromotionpolicyBean.setProductId(pid);
			getproductpromotionpolicyBean.setCurrency("CNY");
			getproductpromotionpolicyCall.setData(getproductpromotionpolicyBean);
			getproductpromotionpolicyCall.callService();		
			
			Logger.verifyEquals("201",getproductpromotionpolicyCall.getString("Code"), "验证返回Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetProductPromotionPolicy_005() {
		Logger.start(true,"获取买手商品促销策略信息-product不匹配");
		try {
			Integer sellerid = GodmchManageCallService.CreateSellerMch();
			String pid =TestDataManager.getRandomUUID().toString();
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(sellerid, 4);
			createpromotionBean.setProductIdList(Arrays.asList(pid));
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);

			getproductpromotionpolicyBean.setSellerId(sellerid);
			getproductpromotionpolicyBean.setCurrency("CNY");
			getproductpromotionpolicyBean.setProductId(pid+1);
			getproductpromotionpolicyCall.setData(getproductpromotionpolicyBean);
			getproductpromotionpolicyCall.callService();		
			
			Logger.verifyEquals("200",getproductpromotionpolicyCall.getString("Code"), "验证返回Code");
			Logger.verifyEquals(null, getproductpromotionpolicyCall.getData(), "验证返回Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetProductPromotionPolicy_006() {
		Logger.start(true,"获取买手商品促销策略信息-sellerid与product不一致");
		try {
			Integer sellerid = GodmchManageCallService.CreateSellerMch();
			String pid =TestDataManager.getRandomUUID().toString();
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(sellerid, 4);
			createpromotionBean.setProductIdList(Arrays.asList(pid));
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
			

			getproductpromotionpolicyBean.setSellerId(3383);
			getproductpromotionpolicyBean.setProductId(pid);
			getproductpromotionpolicyBean.setCurrency("CNY");
			getproductpromotionpolicyCall.setData(getproductpromotionpolicyBean);
			getproductpromotionpolicyCall.callService();		
			
			Logger.verifyEquals("200",getproductpromotionpolicyCall.getString("Code"), "验证返回Code");
			Logger.verifyEquals(null, getproductpromotionpolicyCall.getData(), "验证返回Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetProductPromotionPolicy_007() {
		Logger.start(true,"获取买手商品促销策略信息-Currency空");
		try {
			Integer sellerid = GodmchManageCallService.CreateSellerMch();
			String pid =TestDataManager.getRandomUUID().toString();
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(sellerid, 4);
			createpromotionBean.setProductIdList(Arrays.asList(pid));
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);

			getproductpromotionpolicyBean.setSellerId(sellerid);
			getproductpromotionpolicyBean.setProductId(pid);
//			getproductpromotionpolicyBean.setCurrency("CNY");
			getproductpromotionpolicyCall.setData(getproductpromotionpolicyBean);
			getproductpromotionpolicyCall.callService();		
			
			Logger.verifyEquals("201",getproductpromotionpolicyCall.getString("Code"), "验证返回Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetProductPromotionPolicy_008() {
		Logger.start(true,"获取买手商品促销策略信息-Currency不匹配");
		try {
			Integer sellerid = GodmchManageCallService.CreateSellerMch();
			String pid =TestDataManager.getRandomUUID().toString();
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(sellerid, 4);
			createpromotionBean.setProductIdList(Arrays.asList(pid));
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);

			getproductpromotionpolicyBean.setSellerId(sellerid);
			getproductpromotionpolicyBean.setCurrency("JPY");
			getproductpromotionpolicyBean.setProductId(pid);
			getproductpromotionpolicyCall.setData(getproductpromotionpolicyBean);
			getproductpromotionpolicyCall.callService();		
			
			Logger.verifyEquals("200",getproductpromotionpolicyCall.getString("Code"), "验证返回Code");
			Logger.verifyEquals(null, getproductpromotionpolicyCall.getData(), "验证返回Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}